package cn.jinzhu.order.service;

import cn.jinzhu.order.mapper.OrderMapper;
import cn.jinzhu.order.pojo.Order;
import cn.jinzhu.order.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Slf4j
@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RestTemplate restTemplate;

//    public Order queryOrderById(Long orderId) {
//        // 1.查询订单
//        Order order = orderMapper.findById(orderId);
//        // 4.返回
//        return order;
//    }
    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);

        // 2.查询用户
//        User user = restTemplate.getForObject("http://localhost:8081/user/"  + order.getUserId(), User.class);
        log.info("查询用户服务");
        User user = restTemplate.getForObject("http://user-service/user/"  + order.getUserId(), User.class);
        // 3.设置用户
        order.setUser(user);
        // 4.返回
        return order;
    }
}
